<%- include('../layout') %>

<% contentFor('body') { %>
<% currentPath = '/animals' %>
<div class="container-fluid">
  <div class="d-flex justify-content-between align-items-center mb-4">
    <h2>编辑动物</h2>
    <a href="/admin/animals" class="btn btn-secondary">返回列表</a>
  </div>
  
  <div class="card">
    <div class="card-body">
      <form action="/admin/animals/edit/<%= animal.id %>" method="post">
        <div class="mb-3">
          <label for="name" class="form-label">动物名称 *</label>
          <input type="text" class="form-control" id="name" name="name" value="<%= animal.name %>" required>
        </div>
        <div class="mb-3">
          <label for="categoryId" class="form-label">分类 *</label>
          <select class="form-select" id="categoryId" name="categoryId" required>
            <option value="">请选择分类</option>
            <% categories.forEach(category => { %>
            <option value="<%= category.id %>" <%= animal.categoryId === category.id ? 'selected' : '' %> style="color: <%= category.color %>;">
              <%= category.icon ? `<i class="fa ${category.icon}"></i> ` : '' %><%= category.name %>
            </option>
            <% }); %>
          </select>
        </div>
        <div class="mb-3">
          <label for="imageUrl" class="form-label">主图URL *</label>
          <input type="text" class="form-control" id="imageUrl" name="imageUrl" value="<%= animal.imageUrl %>" required>
          <small class="form-text text-muted">请输入动物主图的完整URL地址</small>
        </div>
        <div class="mb-3">
          <label for="shortDescription" class="form-label">简短描述</label>
          <textarea class="form-control" id="shortDescription" name="shortDescription" rows="3"><%= animal.shortDescription || '' %></textarea>
        </div>
        <div class="mb-3">
          <label for="classification" class="form-label">分类学信息</label>
          <input type="text" class="form-control" id="classification" name="classification" value="<%= animal.classification || '' %>" placeholder="如：脊索动物门，哺乳纲，食肉目">
        </div>
        <div class="d-flex gap-2">
          <button type="submit" class="btn btn-primary">保存</button>
          <a href="/admin/animals" class="btn btn-secondary">取消</a>
        </div>
      </form>
    </div>
  </div>
</div>
<% } %>